from sqlalchemy import (
    Column,
    Index,
    Integer,
    Text,
    Unicode,
    ForeignKey
)
from sqlalchemy.orm import relationship
from .meta import Base

class User(Base):
    __tablename__='users'
    id=Column(Integer,primary_key=True)
    name=Column(Unicode(50),nullable=True,unique=True)
    password=Column(Unicode(100),nullable=True)
    email=Column(Unicode(50))
    group_id=Column(Integer,ForeignKey('groups.id'))
    group=relationship("Group",backref='users')

    def has_permission(self,permission):
        for perm in self.group.permissions:
            if perm.name==permission:
                return True
            return False

